package com.qk.controller;


import com.qk.commom.PageResult;
import com.qk.commom.Result;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class ActivityController {
    @Autowired
    private ActivityService activityService;
    /**
     * 2删除活动
     * @return
     */
    @DeleteMapping("/activities/{id}")
    public Result delete(@PathVariable Integer id) {
        activityService.deleteById(id);
        return Result.success();
    }

    /**
     * 3添加活动
     * @return
     */
    @PostMapping("/activities")
    public Result addActivity(@RequestBody Activity activity) {
        activityService.addActivity(activity);
        return Result.success();
    }
    /**
     * 4根据·id查询·
     * @return
     */
    @GetMapping("/activities/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("查询活动id为{}",id);
        Activity activity = activityService.getById(id);
        return Result.success(activity);
    }
    /**
     * 5修改活动·
     * @return
     *  */
    @PutMapping("/activities")
    public Result update(@RequestBody Activity activity) {
        log.info("修改活动: {}", activity);
        activityService.update(activity);
        return Result.success();
    }

    /**
     * 6查询指定类型活动
     *
     * @return
     */
    @GetMapping("/activities/type/{type}")
    public Result listByType(@PathVariable Integer type) {
        log.info("查询指定类型活动: {}", type);
        List<Activity> activities = activityService.listByType(type);
        return Result.success(activities);
    }
    /**
     * 列表查询
     *
     *
     * @return
     */
    @GetMapping("/activities")
    public Result listActivity( @RequestParam(required = false) Integer channel,Integer type,Integer status,
                                  @RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer pageSize){
        log.info("列表查询: {} {} {}", channel ,type,status);
        PageResult<Activity> pageResult = activityService.listActivity(channel,type,status,page,pageSize);
        return Result.success(pageResult);







    }
    /**
     * 查询所有活动
     *
     * @return
     */



}
